package com.uitls.utils;

import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;

import gnu.trove.THashMap;
import gnu.trove.THashSet;
import gnu.trove.TIntObjectHashMap;
import gnu.trove.TLinkedList;

/**
 * GUN.TROVE是比java.util.collection更快的集合框架，其实现原理是直接在原语上直接操作集合类的框架。
 * 框架是轻量级的，且速度很快，上手也很容易，内存占用HashMap等都少，源于Leakcanary源码分析。
 */
public class CollectionUtil {

    static boolean trove = true;

    static {
        if (System.getProperty("trove").equalsIgnoreCase("true"))
            trove = true;
    }

    public static Map getHashMap() {
        if (trove) {
            return new THashMap();
        } else {
            return new HashMap();
        }
    }

    public static TIntObjectHashMap getHashMap2() {
        return new TIntObjectHashMap();
    }


    public static Map getHashMap(int capacity) {
        if (trove) {
            return new THashMap(capacity);
        } else {
            return new HashMap(capacity);
        }
    }

    public static Set getHashSet() {
        if (trove) {
            return new THashSet();
        } else {
            return new HashSet();
        }
    }

    public static Set getHashSet(int capacity) {
        if (trove) {
            return new THashSet(capacity);
        } else {
            return new HashSet(capacity);
        }
    }

    public static List getLinkedList() {
        if (trove) {
            return new TLinkedList();
        } else {
            return new LinkedList();
        }
    }

}
